package com.example.wotu;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLOpen extends SQLiteOpenHelper {
    public MySQLOpen(Context context){
        super(context,"mose.db",null,1);
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL("CREATE TABLE use(" +
                "useid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "usepic TEXT," +
                "account VARCHAR(10)," +
                "password VARCHAR(10)," +
                "Createtime VARCHAR(100)," +
                "usejs VARCHAR(200)," +
                "finaltime VARCHAR(100)," +
                "usetruef BOOLEAN)");
        sqLiteDatabase.execSQL("CREATE TABLE novel(" +
                "novelid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "useid INTEGER," +
                "fwl VARCHAR(2)," +
                "novelpath TEXT," +
                "novelpic TEXT," +
                "novelname VARCHAR(100)," +
                "noveljs TEXT)");
        sqLiteDatabase.execSQL("CREATE TABLE chapter(" +
                "chapterid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "novelid INTEGER," +
                "chaptpath TEXT," +
                "chapxl INTEGER," +
                "chapname VARCHAR(100)," +
                "content TEXT)");
        sqLiteDatabase.execSQL("CREATE TABLE recod(" +
                "recodid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "novelid INTEGER," +
                "chapterid INTEGER," +
                "readjl VARCHAR(100))");
        sqLiteDatabase.execSQL("CREATE TABLE updatebook(" +
                "updateid INTEGER PRIMARY KEY AUTOINCREMENT," +
                "bookversion VARCHAR(5)," +
                "updatetime VARCHAR(100)," +
                "updatecont TEXT)");
    }

    //软件版本号发生改变时调用（i=1，il=2)
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
        //如我1，到最新版4时，怎样处理之间其余版本的数据？解决：switch没有break，确定它每个都执行
//        switch(arg2){
//            case 1:
//                db.execSQL(第一个版本的建表语句);
//            case 2:
//                db.execSQL(第二个版本的建表语句);
//            case 3:
//                db.execSQL(第三个版本的建表语句);
//        }
//        for(int v=old+1;v<=newVersion;v++){
//            if(v==2) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (1,2,1)");
//            if(v==3) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (3,4,1)");
//            if(v==4) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (5,6,1)");
//            if(v==5) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (7,8,1)");
//            if(v==6) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (9,10,1)");
//            if(v==7) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (11,12,1)");
//            if(v==8) db.execSQL("insert into rj(rjtime,rjtxt,uid) values (13,14,1)");
//        }
    }
}
